import 'package:flutter/material.dart';
import 'package:flutter_animation/first_page.dart';
import 'package:flutter_animation/second_page.dart';
import 'package:flutter_animation/third_page.dart';
import 'package:flutter_animation/utils/constant.dart';

class HomePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _HomePageState();
  }

}


class _HomePageState extends State<HomePage> {

  int _currentIndex = 0;
  late List<Widget> _pages;

  @override
  void initState() {
    super.initState();

    _pages = [FirstPage(), SecondPage(), ThirdPage()];


  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
          onTap: (int index) {
            _bottomNavigationBarTap(index);
          },
          selectedFontSize: 10.0,
          unselectedFontSize: 10.0,
          type: BottomNavigationBarType.fixed,
          fixedColor: Color(0xFFCA5116),
          unselectedItemColor: Color(0xFF191F25),
          currentIndex: _currentIndex,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Image(width: 28,height: 28, image: AssetImage('assets/images/ky_tabbar_chat_normal.png')),
              activeIcon: Image(width: 28,height: 28,image: AssetImage('assets/images/ky_tabbar_chat_selected.png')),
              label: '首页',
              tooltip: Constant.firstNavigationBarItemToolTip,
            ),
            BottomNavigationBarItem(
              icon: Image(width: 28,height: 28, image: AssetImage('assets/images/ky_tabbar_clue_normal.png')),
              activeIcon: Image(width: 28,height: 28,image: AssetImage('assets/images/ky_tabbar_clue_selected.png')),
              label: '列表',
              tooltip: Constant.secondNavigationBarItemToolTip,
            ),
            BottomNavigationBarItem(
              icon: Image(width: 28,height: 28, image: AssetImage('assets/images/ky_tabbar_mine_normal.png')),
              activeIcon: Image(width: 28,height: 28,image: AssetImage('assets/images/ky_tabbar_mine_selected.png')),
              label: '我的',
              tooltip: Constant.thirdNavigationBarItemToolTip,
            ),
          ]
      ),
//      body: pages[_currentIndex],
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
    );
  }


  void _bottomNavigationBarTap(int index){
    setState(() {
      _currentIndex = index;
    });
  }

}